require "#{RAILS_ROOT}/app/classes/irt/irt_model"

#* cat_model.rb
#* Copyright (C) 2010  Embian Inc.
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or 
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with This program.  If not, see <http://www.gnu.org/licenses/>.
#  
#* Extends IRTModel class
#* Author: KyoungMo Yang(E-mail : mo@embian.com)
#* Modified: 2010-12-01
#* References: IRTItem, IRTModel
class CATModel < IRTModel
  
  #* Functionailities
  # * Logistic Function 
  #* Parameters 
  # * [irt_a] : discriment
  # * [irt_b] : difficulty
  # * [irt_c] : guessing
  #* Return
  # * [p] : probability
  #* Note
  # * Formula : P(Θ) = c + (1-c) * (1 / (1 + exp(-1.7*a*(Θ-b))))
  def fun_logistic(theta, irt_a, irt_b=nil, irt_c=nil)
    case @model
      when DICHOTOMOUS_1PL
        p = 1.0 / (1.0 + Math.exp(-1*@D*(theta.to_f-irt_b)))
      when DICHOTOMOUS_2PL
        p = 1.0 / (1.0 + Math.exp(-1*@D*irt_a*(theta.to_f-irt_b)))
      when DICHOTOMOUS_3PL
        p = @irt_c + (1.0 - irt_c)*(1.0 / (1.0 + Math.exp(-1*@D*irt_a*(theta.to_f-irt_b))))
      when POLYTOMOUS_PCM
        #TODO : for POLYTOMOUS MODEL
        raise NotImplementedError
      when POLYTOMOUS_GPCM
        #TODO : for POLYTOMOUS MODEL
        raise NotImplementedError
      else
        raise "IRT Model '#{@model}' is invalid."
    end
    return p
  end
end